<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\ResourceCollection;

class ImageCollection extends ResourceCollection
{
    /**
     * Transform the resource collection into an array.
     *
     * @param  \Illuminate\Http\Request $request
     *
     * @return array
     */
    public function toArray($request)
    {
        return [
            'status' => 'success',
            'msg'    => '',
            'data'   => $this->collection->transform(
                function ($item) {
                    return [
                        'id'         => $item->id,
                        'url'        => $item->url,
                        'like_count' => $item->like_count,
                        'img_like'   => $item->imgLike->count(),
                        'user'       => $item->user ? new UserResource($item->user) : null,
                        'open_id'    => $item->open_id
                    ];
                })
        ];
    }
}
